﻿<%@ Page Title="编辑正则表达式" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="RegexLib.Web.Views.Regex.Edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headContentPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<% RegexInfo regex = (RegexInfo)ViewData.Model; %>
<div class="box">
	<div class="bt">编辑正则表达式</div>
	<div class="bc">
		<form id="TheForm">
<input type="hidden" id="RegexId" name="regexId" value="<%= regex.RegexId %>" />
<fieldset>
	<legend>标题</legend>
	<input type="text" class="input" name="title" maxlength="100" size="200" style="width:520px" value="<%= regex.Title %>" />
</fieldset>
<fieldset>
	<legend>说明</legend>
	<textarea name="description" class="input-ta" cols="200"><%= regex.Description %></textarea>
</fieldset>
<fieldset>
	<legend>模式</legend>
	<textarea name="pattern" class="input-ta" cols="200"><%= regex.Pattern %></textarea>
</fieldset>
<p><button id="SubmitBtn">保存</button></p>
<p><span id="MsgSpan"></span></p>
		</form>
	</div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
<script type="text/javascript">
var c_TheForm;
var c_SubmitBtn;
var c_MsgSpan;

function GetElements()
{
	c_TheForm = YAHOO.util.Dom.get("TheForm");
	c_SubmitBtn = YAHOO.util.Dom.get("SubmitBtn");
	c_MsgSpan = YAHOO.util.Dom.get("MsgSpan");
}

function DoSubmit()
{
	c_SubmitBtn.disabled = true;

	var callback =
	{
		success: function(o)
		{
			var data = YAHOO.lang.JSON.parse(o.responseText);
			if(data.IsError)
			{
				c_MsgSpan.className = "err";
				c_MsgSpan.innerText = data.Message;
				
				c_SubmitBtn.disabled = false;
			}
			else
			{
				window.location = data.Message;
			}
		},
		failure: function(o)
		{
			c_MsgSpan.className = "err";
			c_MsgSpan.innerText = "连接错误。";
			c_SubmitBtn.disabled = false;
		},
		timeout:30000
	};
	YAHOO.util.Connect.setForm(c_TheForm);
	YAHOO.util.Connect.asyncRequest("POST", "/Regex/EditSubmit/", callback, null);
}

function init()
{
	GetElements();
	YAHOO.util.Event.addListener(c_SubmitBtn, "click", DoSubmit);
}

YAHOO.util.Event.onDOMReady(init);
</script>
</asp:Content>
